package com.guocheng.common.exception;

import com.guocheng.entity.AjaxResult;
import org.apache.shiro.ShiroException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

@RestControllerAdvice
/**拦截Controller层的异常*/
public class ServiceException extends RuntimeException{


    @ExceptionHandler(ShiroException.class)
    public AjaxResult ShiroException(Exception e, HttpServletRequest request){
        return AjaxResult.error().data(e);
    }

    @ExceptionHandler(Exception.class)
    public AjaxResult exception(Exception e, HttpServletRequest request){
        e.printStackTrace();
        return AjaxResult.error(e.toString());
    }
}
